var _serviceURL = '/69mark/web';// 必须设置
$(function() {
	doPage(1);
});

function doPage(page){
	var name = $("#serchName").val();
	$.ajax({
   		type : "POST",
   		url : _serviceURL+"/toListAllSecSkill.do",
   		cache : false,
   		//data : "userName="+userName+"&isAuth="+isAuth+"&sex="+sex+"&pageNo="+pageNo+"&pageSize="+pageSize,
   		data : "pageNo="+page+"&pageSize=10&name="+name,
   		dataType : 'json',
   		success : function(data) {
   			var result = "";
   			for(var i=0;i<data.menuList.length;i++){
   				result += "<tr>";
   				result += "<td>"+data.menuList[i].tag_name+"</td>";
   				result += "<td>"+data.menuList[i].name+"</td>";
   				result += "<td>";
   				result += "￥"+data.menuList[i].tag_money+"";
   				result += "</td>";
   				result += "<td>";
   				result += "<a href=\"javascript:void(0);\" title=\"修改\" class=\"chang\" onclick=\"sgthShow('"+data.menuList[i].tag_id+"','"+data.menuList[i].category_id+"','"+data.menuList[i].tag_name+"','"+data.menuList[i].tag_money+"','"+data.menuList[i].tag_content+"')\">修改</a>";
   				result += "<a href=\"\" onclick=\"delfuncitem('"+data.menuList[i].tag_id+"');return false;\" style=\"margin-left:10px;\" title=\"删除\">删除</a>";
   				result += "</td>";
   				result += "</tr>";
   			}
   			
   			$("#heightList").html(result);
   			$("#page_user").html(data.navi);
   			
   			$("#serchName").val("");
   		}
	})
	
}

//身高搜索
function serchName(){
	doPage(1);
}

//删除
function delfuncitem(thisid){
    layer.confirm('确定删除？',{btn:['确定','取消']},function(){
            $.ajax({
                type:'POST',
                url:_serviceURL+'/toDeleteSecSkillId.do',
                data:'id='+thisid,
                dataType : 'json',
                success:function(data){
                    if(data==1){
                        layer.msg('删除成功',{
                            time: 2000,
                        });
                        doPage(1);
                    }else{
                        layer.msg('删除失败',{
                            time: 2000,
                        });
                    }
                }
            });
        }
    );
}

function saveSecSkill(){
	var categoryId = $("select option:selected").attr("value");
	var tagName = $("#tagName").val();
	var tagMoney = $("#tagMoney").val();
	var tagContent = $("#tagContent").val();
	
	if (tagName =='' || tagMoney =='' || categoryId == '0') {
		return false;
	}
	
	$.ajax({
        type:'POST',
        url:_serviceURL+'/toSaveSecSkill.do',
        data:'categoryId='+categoryId+'&tagName='+tagName+"&tagMoney="+tagMoney+"&tagContent="+tagContent,
        dataType : 'json',
        success:function(data){
            if(data==1){
            	$("#tagName").val("");
            	$("#tagMoney").val("");
            	$("#tagContent").val("");
            	$("#select_value option[value='0']").attr("selected", "selected");
            	$(".sgtk2").css("display", "none");
				doPage(1);
            }
        }
    });
}

//
function sgthShow(tagId,categoryId,tagName,tagMoney,tagContent){
	$(".sgtk3").show();
	$("#uselect_value option[value='"+categoryId+"']").attr("selected", "selected");
	$("#tagId").val(tagId);
	$("#uTagName").val(tagName);
	$("#uTagMoney").val(tagMoney);
	$("#uTagContent").val(tagContent);
}

function updateSecSkill(){
	
	var tagId = $("#tagId").val();
	var tagName = $("#uTagName").val();
	var tagMoney = $("#uTagMoney").val();
	var categoryId = $("#uselect_value option:selected").attr("value");
	var tagContent = $("#uTagContent").val();

	if (tagName =='' || tagMoney =='' || categoryId == '') {
		return false;
	}
	
	$.ajax({
        type:'POST',
        url:_serviceURL+'/toUpdateSecSkillId.do',
        data:'tagId='+tagId+'&tagName='+tagName+'&tagMoney='+tagMoney+"&categoryId="+categoryId+"&tagContent="+tagContent,
        dataType : 'json',
        success:function(data){
            if(data==1){
            	$(".sgtk3").css("display", "none");
				doPage(1);
            }
        }
    });
}


